let axios = require("axios").default
axios.defaults.baseURL = "https://api.weixin.qq.com/"

axios.interceptors.response.use(
	response => {
		if (response.data.errcode != undefined && response.data.errcode != 0) {
			let e = new Error("wechat can't respone")
			e.data = response.data
			throw e
		}
		return response
	},
	() => {

	}
)
async function getCode2accessToken({appid, secret, js_code, grant_type = "authorization_code"}) {
	let data = (await axios.get("/sns/jscode2session", {params: {appid, secret, js_code, grant_type}})).data
	/* 	return {
		session_key: 'BX85DoSOtqePMgjlduwL7g==',
		openid: "oDtM65GDl4SMa94qfkeBhX8FN1z8",
		//'oDtM65GDl4SMa94qfkeBhX8FN1z8'
		//oeO7Mwr6y_5C_kFCkGQ4mwMBnskc
	}
	console.log(data) */
	return data
}
module.exports = {getCode2accessToken}
